package com.foreknow.elm.controller;

import com.foreknow.elm.po.Business;
import com.foreknow.elm.service.BusinessService;
import com.foreknow.elm.service.impl.BusinessServiceImpl;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

public class BusinessController {
    /**
     * HttpServletRequest Servlet中的请求对象
     * 里面会提供一方法，用于获取前端传递到后台的请求参数
     * 客户端向服务问端请求的URL地址
     *  http://localhost:8080/elm/BusinessController/listBusinessByOrderTypeId?orderTypeId=1
     * @param request
     * @return
     */
    public Object listBusinessByOrderTypeId(HttpServletRequest request) {
        //1. 获取前台的请求参数
        String orderTypeId = request.getParameter("orderTypeId");
        //2. 调用Service中的方法
        BusinessService businessService = new BusinessServiceImpl();
        List<Business> list = businessService.listBusinessByOrderTypeId(Integer.parseInt(orderTypeId));
        return list;
    }

    /**
     * 根据商家编号查询商家信息
     * 前端发送的URL地址：
     * http://localhost:8080/elm/BusinessController/getBusinessById?businessId=10001
     * @param request
     * @return
     */
    public Object getBusinessById(HttpServletRequest request) {
        String businessId = request.getParameter("businessId");
        BusinessService businessService = new BusinessServiceImpl();
        Business business = businessService.
                getBusinessById(Integer.parseInt(businessId));
        return business;
    }
}
